/*
 * PortletPanelDescarga.java
 *
 * Created on November 8, 2007, 10:12 AM
 * Copyright fsanchez
 */
package gestionbaseem;

import com.computec.baseem.constantes.ConstantesGenerales;
import com.computec.baseem.delegate.BaseEmDelegate;
import com.computec.baseem.exception.BaseEmException;
import com.computec.baseem.source.BaseEmWebSource;
import com.src.computec.radar.services.utilities.actualizaciones.delegate.ActualizacionesDelegate;
import com.src.computec.radar.services.utilities.actualizaciones.exception.ActualizacionesException;
import com.src.computec.radar.services.utilities.dto.BaseEmDto;
import com.src.computec.radar.services.utilities.dto.ClienteDto;
import com.src.computec.radar.services.utilities.dto.FileManagerDto;
import com.src.computec.radar.services.utilities.dto.NodoDto;
import com.src.computec.radar.services.utilities.dto.ProveedorDto;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.faces.FacesException;
import com.sun.rave.web.ui.component.Form;
import com.sun.rave.web.ui.component.ThemeLinks;
import javax.faces.component.html.HtmlPanelGrid;
import com.sun.rave.web.ui.component.PanelGroup;
import javax.faces.component.html.HtmlSelectOneMenu;
import com.sun.jsfcl.data.DefaultSelectItemsArray;
import javax.faces.component.UISelectItems;
import com.sun.rave.web.ui.component.DropDown;
import com.sun.rave.web.ui.model.SingleSelectOptionsList;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlDataTable;
import com.sun.jsfcl.data.DefaultTableDataModel;
import javax.faces.component.UIColumn;
import com.sun.rave.web.ui.component.Calendar;
import javax.faces.component.html.HtmlCommandButton;
import javax.faces.validator.LongRangeValidator;
import javax.faces.validator.DoubleRangeValidator;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import javax.faces.application.FacesMessage;
import javax.faces.component.html.HtmlInputHidden;
import com.sun.rave.web.ui.component.Alert;
import javax.faces.event.ValueChangeEvent;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.component.html.HtmlPanelGroup;
import com.sun.rave.web.ui.component.TextArea;
import javax.faces.component.html.HtmlInputText;


public class PortletPanelDescarga extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Creator-managed Component Definition">
    
    private int __placeholder;
    
    private ThemeLinks themeLinks1 = new ThemeLinks();
    
    public ThemeLinks getThemeLinks1() {
	return themeLinks1;
    }
    
    public void setThemeLinks1(ThemeLinks t) {
	this.themeLinks1 = t;
    }
    
    private Form form1 = new Form();
    
    public Form getForm1() {
	return form1;
    }
    
    public void setForm1(Form f) {
	this.form1 = f;
    }

    private HtmlPanelGrid gridPanelContainer = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanelContainer() {
        return gridPanelContainer;
    }

    public void setGridPanelContainer(HtmlPanelGrid hpg) {
        this.gridPanelContainer = hpg;
    }

    private HtmlPanelGrid topGridPanel = new HtmlPanelGrid();

    public HtmlPanelGrid getTopGridPanel() {
        return topGridPanel;
    }

    public void setTopGridPanel(HtmlPanelGrid hpg) {
        this.topGridPanel = hpg;
    }

    private HtmlPanelGrid bottomGridPanel = new HtmlPanelGrid();

    public HtmlPanelGrid getBottomGridPanel() {
        return bottomGridPanel;
    }

    public void setBottomGridPanel(HtmlPanelGrid hpg) {
        this.bottomGridPanel = hpg;
    }

    private DropDown dropDownClientes = new DropDown();

    public DropDown getDropDownClientes() {
        return dropDownClientes;
    }

    public void setDropDownClientes(DropDown dd) {
        this.dropDownClientes = dd;
    }

    private HtmlOutputText outputTextCliente = new HtmlOutputText();

    public HtmlOutputText getOutputTextCliente() {
        return outputTextCliente;
    }

    public void setOutputTextCliente(HtmlOutputText hot) {
        this.outputTextCliente = hot;
    }

    private HtmlOutputText outputTextNodo = new HtmlOutputText();

    public HtmlOutputText getOutputTextNodo() {
        return outputTextNodo;
    }

    public void setOutputTextNodo(HtmlOutputText hot) {
        this.outputTextNodo = hot;
    }

    private DropDown dropDownNodos = new DropDown();

    public DropDown getDropDownNodos() {
        return dropDownNodos;
    }

    public void setDropDownNodos(DropDown dd) {
        this.dropDownNodos = dd;
    }

    private HtmlDataTable dataTableBases = new HtmlDataTable();

    public HtmlDataTable getDataTableBases() {
        return dataTableBases;
    }

    public void setDataTableBases(HtmlDataTable hdt) {
        this.dataTableBases = hdt;
    }

    private DefaultTableDataModel dataTable1Model = new DefaultTableDataModel();

    public DefaultTableDataModel getDataTable1Model() {
        return dataTable1Model;
    }

    public void setDataTable1Model(DefaultTableDataModel dtdm) {
        this.dataTable1Model = dtdm;
    }

    private UIColumn nodo = new UIColumn();

    public UIColumn getNodo() {
        return nodo;
    }

    public void setNodo(UIColumn uic) {
        this.nodo = uic;
    }

    private HtmlOutputText outputText1 = new HtmlOutputText();

    public HtmlOutputText getOutputText1() {
        return outputText1;
    }

    public void setOutputText1(HtmlOutputText hot) {
        this.outputText1 = hot;
    }

    private HtmlOutputText outputText2 = new HtmlOutputText();

    public HtmlOutputText getOutputText2() {
        return outputText2;
    }

    public void setOutputText2(HtmlOutputText hot) {
        this.outputText2 = hot;
    }

    private UIColumn clienteProducto = new UIColumn();

    public UIColumn getClienteProducto() {
        return clienteProducto;
    }

    public void setClienteProducto(UIColumn uic) {
        this.clienteProducto = uic;
    }

    private HtmlOutputText outputText3 = new HtmlOutputText();

    public HtmlOutputText getOutputText3() {
        return outputText3;
    }

    public void setOutputText3(HtmlOutputText hot) {
        this.outputText3 = hot;
    }

    private HtmlOutputText outputText4 = new HtmlOutputText();

    public HtmlOutputText getOutputText4() {
        return outputText4;
    }

    public void setOutputText4(HtmlOutputText hot) {
        this.outputText4 = hot;
    }

    private UIColumn numOrden = new UIColumn();

    public UIColumn getNumOrden() {
        return numOrden;
    }

    public void setNumOrden(UIColumn uic) {
        this.numOrden = uic;
    }

    private HtmlOutputText outputText5 = new HtmlOutputText();

    public HtmlOutputText getOutputText5() {
        return outputText5;
    }

    public void setOutputText5(HtmlOutputText hot) {
        this.outputText5 = hot;
    }

    private HtmlOutputText outputText6 = new HtmlOutputText();

    public HtmlOutputText getOutputText6() {
        return outputText6;
    }

    public void setOutputText6(HtmlOutputText hot) {
        this.outputText6 = hot;
    }

    private UIColumn ciclo = new UIColumn();

    public UIColumn getCiclo() {
        return ciclo;
    }

    public void setCiclo(UIColumn uic) {
        this.ciclo = uic;
    }

    private HtmlOutputText outputText7 = new HtmlOutputText();

    public HtmlOutputText getOutputText7() {
        return outputText7;
    }

    public void setOutputText7(HtmlOutputText hot) {
        this.outputText7 = hot;
    }

    private UIColumn fechaPublicacion = new UIColumn();

    public UIColumn getFechaPublicacion() {
        return fechaPublicacion;
    }

    public void setFechaPublicacion(UIColumn uic) {
        this.fechaPublicacion = uic;
    }

    private HtmlOutputText outputText8 = new HtmlOutputText();

    public HtmlOutputText getOutputText8() {
        return outputText8;
    }

    public void setOutputText8(HtmlOutputText hot) {
        this.outputText8 = hot;
    }

    private UIColumn cant = new UIColumn();

    public UIColumn getCant() {
        return cant;
    }

    public void setCant(UIColumn uic) {
        this.cant = uic;
    }

    private HtmlOutputText outputText9 = new HtmlOutputText();

    public HtmlOutputText getOutputText9() {
        return outputText9;
    }

    public void setOutputText9(HtmlOutputText hot) {
        this.outputText9 = hot;
    }

    private UIColumn fechaDescarga = new UIColumn();

    public UIColumn getFechaDescarga() {
        return fechaDescarga;
    }

    public void setFechaDescarga(UIColumn uic) {
        this.fechaDescarga = uic;
    }

    private HtmlOutputText outputText10 = new HtmlOutputText();

    public HtmlOutputText getOutputText10() {
        return outputText10;
    }

    public void setOutputText10(HtmlOutputText hot) {
        this.outputText10 = hot;
    }

    private UIColumn descripcion = new UIColumn();

    public UIColumn getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(UIColumn uic) {
        this.descripcion = uic;
    }

    private HtmlOutputText outputText11 = new HtmlOutputText();

    public HtmlOutputText getOutputText11() {
        return outputText11;
    }

    public void setOutputText11(HtmlOutputText hot) {
        this.outputText11 = hot;
    }

    private UIColumn fuenteArchivo = new UIColumn();

    public UIColumn getFuenteArchivo() {
        return fuenteArchivo;
    }

    public void setFuenteArchivo(UIColumn uic) {
        this.fuenteArchivo = uic;
    }

    private HtmlOutputText outputText12 = new HtmlOutputText();

    public HtmlOutputText getOutputText12() {
        return outputText12;
    }

    public void setOutputText12(HtmlOutputText hot) {
        this.outputText12 = hot;
    }

    private HtmlOutputText fechaIni = new HtmlOutputText();

    public HtmlOutputText getFechaIni() {
        return fechaIni;
    }

    public void setFechaIni(HtmlOutputText hot) {
        this.fechaIni = hot;
    }

    private HtmlOutputText fechaFin = new HtmlOutputText();

    public HtmlOutputText getFechaFin() {
        return fechaFin;
    }

    public void setFechaFin(HtmlOutputText hot) {
        this.fechaFin = hot;
    }

    private Calendar calendarInicial = new Calendar();

    public Calendar getCalendarInicial() {
        return calendarInicial;
    }

    public void setCalendarInicial(Calendar c) {
        this.calendarInicial = c;
    }

    private Calendar calendarFinal = new Calendar();

    public Calendar getCalendarFinal() {
        return calendarFinal;
    }

    public void setCalendarFinal(Calendar c) {
        this.calendarFinal = c;
    }

    private HtmlOutputText outputText13 = new HtmlOutputText();

    public HtmlOutputText getOutputText13() {
        return outputText13;
    }

    public void setOutputText13(HtmlOutputText hot) {
        this.outputText13 = hot;
    }

    private HtmlOutputText outputText14 = new HtmlOutputText();

    public HtmlOutputText getOutputText14() {
        return outputText14;
    }

    public void setOutputText14(HtmlOutputText hot) {
        this.outputText14 = hot;
    }

    private HtmlOutputText outputText15 = new HtmlOutputText();

    public HtmlOutputText getOutputText15() {
        return outputText15;
    }

    public void setOutputText15(HtmlOutputText hot) {
        this.outputText15 = hot;
    }

    private HtmlOutputText outputText16 = new HtmlOutputText();

    public HtmlOutputText getOutputText16() {
        return outputText16;
    }

    public void setOutputText16(HtmlOutputText hot) {
        this.outputText16 = hot;
    }

    private HtmlOutputText outputText17 = new HtmlOutputText();

    public HtmlOutputText getOutputText17() {
        return outputText17;
    }

    public void setOutputText17(HtmlOutputText hot) {
        this.outputText17 = hot;
    }

    private HtmlCommandButton buttonConsultar = new HtmlCommandButton();

    public HtmlCommandButton getButtonConsultar() {
        return buttonConsultar;
    }

    public void setButtonConsultar(HtmlCommandButton hcb) {
        this.buttonConsultar = hcb;
    }

    private HtmlCommandButton buttonLimpiar = new HtmlCommandButton();

    public HtmlCommandButton getButtonLimpiar() {
        return buttonLimpiar;
    }

    public void setButtonLimpiar(HtmlCommandButton hcb) {
        this.buttonLimpiar = hcb;
    }

    private HtmlInputHidden hiddenPath = new HtmlInputHidden();

    public HtmlInputHidden getHiddenPath() {
        return hiddenPath;
    }

    public void setHiddenPath(HtmlInputHidden hih) {
        this.hiddenPath = hih;
    }

    private HtmlInputHidden hiddenCodigo = new HtmlInputHidden();

    public HtmlInputHidden getHiddenCodigo() {
        return hiddenCodigo;
    }

    public void setHiddenCodigo(HtmlInputHidden hih) {
        this.hiddenCodigo = hih;
    }

    private HtmlCommandButton buttonDownload = new HtmlCommandButton();

    public HtmlCommandButton getButtonDownload() {
        return buttonDownload;
    }

    public void setButtonDownload(HtmlCommandButton hcb) {
        this.buttonDownload = hcb;
    }

    private Alert alertMessage = new Alert();

    public Alert getAlertMessage() {
        return alertMessage;
    }

    public void setAlertMessage(Alert a) {
        this.alertMessage = a;
    }

    private DropDown dropDownEm = new DropDown();

    public DropDown getDropDownEm() {
        return dropDownEm;
    }

    public void setDropDownEm(DropDown dd) {
        this.dropDownEm = dd;
    }

    private HtmlOutputText outputTextProv = new HtmlOutputText();

    public HtmlOutputText getOutputTextProv() {
        return outputTextProv;
    }

    public void setOutputTextProv(HtmlOutputText hot) {
        this.outputTextProv = hot;
    }

    private HtmlCommandLink linkActionDescarga = new HtmlCommandLink();

    public HtmlCommandLink getLinkActionDescarga() {
        return linkActionDescarga;
    }

    public void setLinkActionDescarga(HtmlCommandLink hcl) {
        this.linkActionDescarga = hcl;
    }

    private HtmlOutputText linkAction1Text = new HtmlOutputText();

    public HtmlOutputText getLinkAction1Text() {
        return linkAction1Text;
    }

    public void setLinkAction1Text(HtmlOutputText hot) {
        this.linkAction1Text = hot;
    }

    private HtmlPanelGroup groupPanel1 = new HtmlPanelGroup();

    public HtmlPanelGroup getGroupPanel1() {
        return groupPanel1;
    }

    public void setGroupPanel1(HtmlPanelGroup hpg) {
        this.groupPanel1 = hpg;
    }

    private HtmlCommandButton dataTableBasesFooterFirstButton = new HtmlCommandButton();

    public HtmlCommandButton getDataTableBasesFooterFirstButton() {
        return dataTableBasesFooterFirstButton;
    }

    public void setDataTableBasesFooterFirstButton(HtmlCommandButton hcb) {
        this.dataTableBasesFooterFirstButton = hcb;
    }

    private HtmlCommandButton dataTableBasesFooterPreviousButton = new HtmlCommandButton();

    public HtmlCommandButton getDataTableBasesFooterPreviousButton() {
        return dataTableBasesFooterPreviousButton;
    }

    public void setDataTableBasesFooterPreviousButton(HtmlCommandButton hcb) {
        this.dataTableBasesFooterPreviousButton = hcb;
    }

    private HtmlCommandButton dataTableBasesFooterNextButton = new HtmlCommandButton();

    public HtmlCommandButton getDataTableBasesFooterNextButton() {
        return dataTableBasesFooterNextButton;
    }

    public void setDataTableBasesFooterNextButton(HtmlCommandButton hcb) {
        this.dataTableBasesFooterNextButton = hcb;
    }

    private HtmlCommandButton dataTableBasesFooterLastButton = new HtmlCommandButton();

    public HtmlCommandButton getDataTableBasesFooterLastButton() {
        return dataTableBasesFooterLastButton;
    }

    public void setDataTableBasesFooterLastButton(HtmlCommandButton hcb) {
        this.dataTableBasesFooterLastButton = hcb;
    }

    private HtmlPanelGrid gridPanelGenerarBase = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanelGenerarBase() {
        return gridPanelGenerarBase;
    }

    public void setGridPanelGenerarBase(HtmlPanelGrid hpg) {
        this.gridPanelGenerarBase = hpg;
    }

    private TextArea textAreaOrdenes = new TextArea();

    public TextArea getTextAreaOrdenes() {
        return textAreaOrdenes;
    }

    public void setTextAreaOrdenes(TextArea ta) {
        this.textAreaOrdenes = ta;
    }

    private HtmlCommandButton buttonGenerar = new HtmlCommandButton();

    public HtmlCommandButton getButtonGenerar() {
        return buttonGenerar;
    }

    public void setButtonGenerar(HtmlCommandButton hcb) {
        this.buttonGenerar = hcb;
    }

    private HtmlCommandButton buttonVer = new HtmlCommandButton();

    public HtmlCommandButton getButtonVer() {
        return buttonVer;
    }

    public void setButtonVer(HtmlCommandButton hcb) {
        this.buttonVer = hcb;
    }

    private HtmlCommandButton buttonLimpiarTextArea = new HtmlCommandButton();

    public HtmlCommandButton getButtonLimpiarTextArea() {
        return buttonLimpiarTextArea;
    }

    public void setButtonLimpiarTextArea(HtmlCommandButton hcb) {
        this.buttonLimpiarTextArea = hcb;
    }

    private HtmlOutputText outputTextNumeroOrden = new HtmlOutputText();

    public HtmlOutputText getOutputTextNumeroOrden() {
        return outputTextNumeroOrden;
    }

    public void setOutputTextNumeroOrden(HtmlOutputText hot) {
        this.outputTextNumeroOrden = hot;
    }

    private HtmlInputText textFieldNumeroOrden = new HtmlInputText();

    public HtmlInputText getTextFieldNumeroOrden() {
        return textFieldNumeroOrden;
    }

    public void setTextFieldNumeroOrden(HtmlInputText hit) {
        this.textFieldNumeroOrden = hit;
    }
    
    // </editor-fold>
    public PortletPanelDescarga() {
	// <editor-fold defaultstate="collapsed" desc="Creator-managed Component Initialization">
	try {
	} catch (Exception e) {
	    log("Page1 Initialization Failure", e);
	    throw e instanceof javax.faces.FacesException ? (FacesException) e: new FacesException(e);
	}
	// </editor-fold>
	// TODO: Add your own initialization code here (optional)
    }

    /** 
     * <p>Return a reference to the scoped data bean.</p>
     */
    protected RequestBeanBaseEm getRequestBeanBaseEm() {
        return (RequestBeanBaseEm)getBean("RequestBeanBaseEm");
    }


    /** 
     * <p>Return a reference to the scoped data bean.</p>
     */
    protected ApplicationBeanBaseEm getApplicationBeanBaseEm() {
        return (ApplicationBeanBaseEm)getBean("ApplicationBeanBaseEm");
    }


    /** 
     * <p>Return a reference to the scoped data bean.</p>
     */
    protected SessionBeanBaseEm getSessionBeanBaseEm() {
        return (SessionBeanBaseEm)getBean("SessionBeanBaseEm");
    }


    /** 
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();		
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here

        // <editor-fold defaultstate="collapsed" desc="Creator-managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("PortletPage1 Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here

    }

    /** 
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    public void preprocess() {
    }

    /** 
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    public void prerender() {
    }

    /** 
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    public void destroy() {
    }

    /** 
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
	 this.dataTableBases.setFirst(0);
    }


    public void buttonConsultar_action() {	
	this.consultarListadoBaseEm(false);	
	 this.dataTableBases.setFirst(0);	
    }
    public void consultarListadoBaseEm(boolean isInitEjecucion){
	String codigoNodo_=(String)this.dropDownNodos.getValue();
	String codigoCliente_=(String)this.dropDownClientes.getValue();	
	String numeroOrden_=(String)this.textFieldNumeroOrden.getValue();
	boolean isNumber_=false;
	if(numeroOrden_!=null && !numeroOrden_.trim().equals("")){
	    isNumber_=this.isNumber(numeroOrden_);
	}
        BaseEmDelegate delegate_=new BaseEmDelegate();
	ProveedorDto proDto_=new ProveedorDto();
	proDto_.setCodigoProveedor(this.getSessionBeanBaseEm().getCodigoEM());
	NodoDto nodoDto_=new NodoDto();
	nodoDto_.setCodigoNodo(codigoNodo_);
	ClienteDto cliDto_=new ClienteDto();
	cliDto_.setCodigoCliente(codigoCliente_);
	
	Date fechaI_=this.calendarInicial.getSelectedDate();
	Date fechaF_=this.calendarFinal.getSelectedDate();
	
	if((numeroOrden_!=null && !numeroOrden_.trim().equals("") && isNumber_) || (numeroOrden_==null) ||(numeroOrden_!=null && numeroOrden_.trim().equals("")) ){	    
	
		if(fechaF_!=null && fechaI_!=null){
		    java.util.Calendar cal_=java.util.Calendar.getInstance();
		    cal_.setTime(fechaF_);
		    cal_.add(java.util.Calendar.HOUR_OF_DAY, 23);
		    cal_.add(java.util.Calendar.MINUTE,59);
		    fechaF_=cal_.getTime();


		    if(fechaI_.before(fechaF_)){
			try{
			    List baseEmList_=delegate_.getListadoBases(proDto_, nodoDto_, cliDto_,fechaI_,fechaF_,numeroOrden_);
			    if(baseEmList_!=null && baseEmList_.size()>0){
				this.getSessionBeanBaseEm().setBaseEmList(baseEmList_);
				this.getSessionBeanBaseEm().setRenderedTable(true);				
				this.getSessionBeanBaseEm().setRenderedAlert(false);				
			    }else{
				this.getSessionBeanBaseEm().setRenderedTable(false);
				this.getSessionBeanBaseEm().setRenderedAlert(true);			
				this.setMensajeAlert("warning", "Advertencia", BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("NoExistenRegistros"), true);

			    }
			      this.buttonVer.setValue("Max.");
			      this.getSessionBeanBaseEm().setRenderedPanelGridGeneracion(false);
			}catch(BaseEmException bex){
				bex.printStackTrace();
				this.setMensajeAlert("error", "Error",BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("ErrorSistema"), true);
				this.getSessionBeanBaseEm().setRenderedTable(false);
				this.getSessionBeanBaseEm().setRenderedAlert(true);			
			}
		    }else{
				this.getSessionBeanBaseEm().setRenderedTable(false);
				this.getSessionBeanBaseEm().setRenderedAlert(true);
				this.setMensajeAlert("warning", "Advertencia", BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("WarningFechaFin"), true);
		    }
		}else{
		    try{
			List baseEmList_=delegate_.getListadoBases(proDto_, nodoDto_, cliDto_,null,null, numeroOrden_);
			   if(baseEmList_!=null && baseEmList_.size()>0){
				this.getSessionBeanBaseEm().setBaseEmList(baseEmList_);
				this.getSessionBeanBaseEm().setRenderedTable(true);
			    }else{
				this.getSessionBeanBaseEm().setRenderedTable(false);
				if(!isInitEjecucion){
				    this.getSessionBeanBaseEm().setRenderedAlert(true);
				    this.setMensajeAlert("warning", "Advertencia", BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("NoExistenRegistros"), true);
				}
			    }		
		    }catch(BaseEmException bex){
			bex.printStackTrace();
			this.setMensajeAlert("error", "Error",BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("ErrorSistema"), true);
			this.getSessionBeanBaseEm().setRenderedTable(false);
			this.getSessionBeanBaseEm().setRenderedAlert(true);
		    }
		}
	}else{
	    this.getSessionBeanBaseEm().setRenderedAlert(true);
	    this.setMensajeAlert("warning", "Advertencia", BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("NumOrdenNAN"), true); 	    
	    this.getSessionBeanBaseEm().setRenderedTable(false);
			
	}
    }
    
    
    public void linkActionFileDownload_action() 
    {
        try
        {
	    
            String relativePath_=(String)this.hiddenPath.getValue();
	    Integer codigoBase_=(Integer)this.hiddenCodigo.getValue();
	  
	    
            String fileDownloaderPath =this.getApplicationBeanBaseEm().getFileDownloaderPath();            
            String idUser = this.getSessionBeanBaseEm().getLdapUser();            
            long longCurrentTimeMillis = System.currentTimeMillis();
            
            com.src.computec.radar.services.base.constantes.ConstantesGenerales constantesServices = com.src.computec.radar.services.base.constantes.ConstantesGenerales.getInstance();
            ConstantesGenerales constantesBase_ = ConstantesGenerales.getInstance();
            
            FileManagerDto fileManagerDto = new FileManagerDto();
            fileManagerDto.setIdDescarga(new Timestamp(longCurrentTimeMillis));
            fileManagerDto.setCodigoResponsable(idUser);
            fileManagerDto.setOrigen(constantesBase_.FILE_ORIGEN);
            fileManagerDto.setRutaArchivo(relativePath_);//   /Manuales/nombrearchivo
            fileManagerDto.setEstado(constantesServices.ACTIVE_STATE);
	    fileManagerDto.setKey(codigoBase_.intValue());
            
            ActualizacionesDelegate actualizacionesDelegate = new ActualizacionesDelegate();
            actualizacionesDelegate.insertFileManagerKey(fileManagerDto);
           //  this.consultarListadoBaseEm(false);
            FacesContext.getCurrentInstance().getExternalContext().redirect(fileDownloaderPath + longCurrentTimeMillis);    
            FacesContext.getCurrentInstance().renderResponse();     
	   
        }
        catch (Exception e) 
        {
            e.printStackTrace();
            this.setMensajeAlert("error", "Error",BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("ErrorSistema"), true);
	    this.getSessionBeanBaseEm().setRenderedAlert(true);
        }     
    }
  
    public void setMensajeAlert(String type, String summary, String detail, boolean visible) 
    {
        if (visible){
            this.alertMessage.setType(type);
            this.alertMessage.setSummary(summary);
            this.alertMessage.setDetail(detail);
            this.alertMessage.setVisible(visible);
        }else{
            this.alertMessage.setVisible(visible);
        }
    }


    public void dropDownEm_processValueChange(ValueChangeEvent event) {	
	 String codigoEM_=(String)this.dropDownEm.getSelected();
	 //System.out.println("CODIGO EM:"+codigoEM_);
	try{
	    if(codigoEM_ != null && !codigoEM_.equals("")) {                
		this.getSessionBeanBaseEm().setNodosOptions(this.getSessionBeanBaseEm().getNodosByProveedorOptions(codigoEM_));
		this.getSessionBeanBaseEm().setCodigoEM(codigoEM_);
	    } else {
		this.getSessionBeanBaseEm().setCodigoEM("");
		this.getSessionBeanBaseEm().setNodosOptions(this.getSessionBeanBaseEm().getNodosByProveedorOptions(""));
	    }
        } catch(Exception e) {
            e.printStackTrace();
            this.setMensajeAlert("error", "Error",BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("ErrorSistema"), true);
	    this.getSessionBeanBaseEm().setRenderedAlert(true);
        }	            
    }


    public void buttonLimpiar_action() {
	
        this.getSessionBeanBaseEm().setBaseEmList(null);
	this.getSessionBeanBaseEm().setRenderedTable(false);
	this.getSessionBeanBaseEm().setRenderedAlert(false);
	this.calendarInicial.setSelectedDate(this.getSessionBeanBaseEm().getDefaultInitDate());
	this.calendarFinal.setSelectedDate(this.getSessionBeanBaseEm().getMaxDate());
	this.dropDownClientes.setSelected("Seleccione...");
	this.dropDownEm.setSelected("Seleccione...");
	this.dropDownNodos.setSelected("Seleccione...");
	this.textFieldNumeroOrden.setValue("");
    }


    public String linkActionDescarga_action() {
	
	BaseEmDelegate delegate_=new BaseEmDelegate();
	List detalleDesc_=null;
	Integer codigoBase_=(Integer)this.hiddenCodigo.getValue();
	String retValue=null;
	  try{
	      
	      detalleDesc_=delegate_.getInfoDescargas(codigoBase_.toString());
	      for(Iterator it=detalleDesc_.iterator();it.hasNext();){
		  BaseEmDto baseDto_=(BaseEmDto)it.next();
		    
		    String idUser=baseDto_.getDescripcion();
		    //System.out.println("idUser:"+idUser+"-"+this.getSessionBeanBaseEm().getFullNamePersonLDAP(idUser));
		    baseDto_.setDescripcion(this.getSessionBeanBaseEm().getFullNamePersonLDAP(idUser));
		    
	      }
	      if(detalleDesc_!=null && detalleDesc_.size()>0){
		    this.getSessionBeanBaseEm().setBaseEmDetalle(detalleDesc_);        
		     retValue= "detalle";
	      }else{
		    this.setMensajeAlert("warning", "Advertencia",BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("NoDetalle"), true);
		    this.getSessionBeanBaseEm().setRenderedAlert(true);		  		  
	      }
		
	  }catch(BaseEmException bex){
	      bex.printStackTrace();
	      this.setMensajeAlert("error", "Error",BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("ErrorSistema"), true);
	      this.getSessionBeanBaseEm().setRenderedAlert(true);
	  }
	   
       return retValue;
    }


    public String dataTableBases_firstPageAction() {
        dataTableBases.setFirst(0);
        return null;
    }


    public String dataTableBases_previousPageAction() {	 
        int first = dataTableBases.getFirst() - dataTableBases.getRows();
        if (first < 0) {
            first = 0;
        }
        dataTableBases.setFirst(first);
        return null;
    }


    public String dataTableBases_nextPageAction() {
        int first = dataTableBases.getFirst() + dataTableBases.getRows();	
        dataTableBases.setRowIndex(first);
        if (dataTableBases.isRowAvailable()) {
            dataTableBases.setFirst(first);
        }
        return null;
    }


    public String dataTableBases_lastPageAction() {
        int first = dataTableBases.getFirst();
        while (true) {
            dataTableBases.setRowIndex(first + 1);
            if (dataTableBases.isRowAvailable()) {
                first++;
            } else {
                break;
            }
        }
        dataTableBases.setFirst(first - (first % dataTableBases.getRows()));
        return null;
    }


    public void buttonGenerar_action() {
	this.getSessionBeanBaseEm().setRenderedAlert(false);
      String ordenes_=(String)this.textAreaOrdenes.getValue();
      ActualizacionesDelegate actDelegate_=new ActualizacionesDelegate();
      ArrayList listOrdenes_=(ArrayList)formatBusqueda(ordenes_);
      com.src.computec.radar.services.base.constantes.ConstantesGenerales.getInstance();
      String tipoBaseNormal_=com.src.computec.radar.services.base.constantes.ConstantesGenerales.TIPO_BASE_EM_NORMAL;
      StringBuffer generadas_=new StringBuffer();
      StringBuffer yaFueronGeneradas_=new StringBuffer();
      StringBuffer noExiste_=new StringBuffer();
      if(listOrdenes_!=null && listOrdenes_.size()>0){
	  for(Iterator it=listOrdenes_.iterator();it.hasNext();){
	      String ordenProc_=(String)it.next();
	      try{
	      boolean[] retGeneracion_=actDelegate_.generarBaseXNumOrden(ordenProc_,tipoBaseNormal_);	  
	      if(retGeneracion_[0]){
		    generadas_.append(",");
		    generadas_.append(ordenProc_)  ;
	      }else if(retGeneracion_[1]){
		    yaFueronGeneradas_.append(",");
		    yaFueronGeneradas_.append(ordenProc_)  ;
	      }
	      if(!retGeneracion_[2]){
		    noExiste_.append(",");
		    noExiste_.append(ordenProc_)  ;
	      }
	      
	      }catch(ActualizacionesException aex){
		  aex.printStackTrace();
		  this.setMensajeAlert("error", "Error",BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("ErrorSistema"), true);
		  this.getSessionBeanBaseEm().setRenderedAlert(true);
	      }
	  }
      }
      generadas_.replace(0, 1, "");
      noExiste_.replace(0, 1,"");
      yaFueronGeneradas_.replace(0,1,"");
	if(!this.getSessionBeanBaseEm().isRenderedAlert()){
		this.getSessionBeanBaseEm().setRenderedAlert(true);
		//BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("InfoGeneracion")
		    this.setMensajeAlert("info", "Informaci\363n", (generadas_.length()>=1?"Seran generadas las bases en segundo plano para las ordenes de proceso: "+generadas_.toString():"")+(noExiste_.length()>=1?" ** Las siguientes bases no han sido cargadas a radar: "+noExiste_.toString():"")+(yaFueronGeneradas_.length()>=1?" *** Las siguientes bases ya habian sido generadas:"+yaFueronGeneradas_.toString():""), true);     
	    }
    }
    
    private List formatBusqueda(String pCodigos) {
        List listBusqueda = new ArrayList();
        int NaN_=0;
	if(pCodigos!=null && !pCodigos.trim().equals("")){
	    String[] busquedaTokens = (pCodigos).split("\n");
	    for(int i=0; i<busquedaTokens.length; i++) {
		String token = busquedaTokens[i].trim();
		if (token != null && !token.equals("") && !listBusqueda.contains(token)) {                
			if (this.isNumber(token)) {
			    listBusqueda.add(token);
			}
			else {
			    NaN_++;
			    //listInconsistencias.add(token);
			}
		}
	    }        
	    if(NaN_>0 && listBusqueda.size()>0 ){
		 this.setMensajeAlert("warning", "Advertencia",BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("NumOrdenError"), true);
		 this.getSessionBeanBaseEm().setRenderedAlert(true);
	    }else if(listBusqueda.size()==0){
		    this.setMensajeAlert("warning", "Advertencia",BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("NumOrdenError"), true);
		    this.getSessionBeanBaseEm().setRenderedAlert(true);
	    }
//	    else{
//		this.getSessionBeanBaseEm().setRenderedAlert(true);
//		this.setMensajeAlert("info", "Informaci\363n", BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("InfoGeneracion"), true);     
//	    }
	}else{
	    this.setMensajeAlert("warning", "Advertencia",BaseEmWebSource.getInstance().getBaseEmWebErrorSetupKey("NumOrdenVacio"), true);
	    this.getSessionBeanBaseEm().setRenderedAlert(true);		
	}	
        return listBusqueda;
    }
    
     private boolean isNumber(String token) {
        try {
            BigInteger bigInteger = new BigInteger(token);
            return true;
        }
        catch(NumberFormatException nfe) {
            return false;
        }
    }


    public String buttonVer_action() {
       if(this.getSessionBeanBaseEm().isRenderedPanelGridGeneracion()){
	   this.buttonVer.setValue("Max.");
	   this.getSessionBeanBaseEm().setRenderedPanelGridGeneracion(false);
       }else{
	   this.buttonVer.setValue("Min.");
	   this.getSessionBeanBaseEm().setRenderedPanelGridGeneracion(true);
       }        
        return null;
    }


    public void buttonLimpiarTextArea_action() {
	this.getSessionBeanBaseEm().setRenderedAlert(false);
	this.textAreaOrdenes.setValue("");   
    }
}
